package com.infonova.education.microservice;

import com.infonova.education.microservice.repository.CustomerRepository;
import com.infonova.education.microservice.repository.OrderPositionRepository;
import com.infonova.education.microservice.repository.OrderRepository;
import com.infonova.education.microservice.repository.ProductRepository;
import com.infonova.education.microservice.repository.entity.Customer;
import com.infonova.education.microservice.repository.entity.Order;
import com.infonova.education.microservice.repository.entity.OrderPosition;
import com.infonova.education.microservice.repository.entity.Product;
import com.infonova.education.microservice.service.OrderService;
import com.thoughtworks.xstream.XStream;
import java.util.HashSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Profile("dev")
public class DemoConfigurer {

    @Autowired
    private ProductRepository productRepository;
    @Autowired
    private CustomerRepository customerRepository;
    @Autowired
    private OrderRepository orderRepository;

    @Autowired
    private OrderService orderService;
    
    @Autowired
    private OrderPositionRepository orderPositionRepository;
            
    @PostConstruct
    public void createDemoData() {
        Product product1 = new Product();
        product1.setName("Product A");
        product1.setPrice(10);

        productRepository.save(product1);

        Product product2 = new Product();
        product2.setName("Product B");
        product2.setPrice(20);
        productRepository.save(product2);

        Product product3 = new Product();
        product3.setName("Product C");
        product3.setPrice(30);
        productRepository.save(product3);

        Customer customer1 = new Customer(10, "Manuel", "Banane");
        customerRepository.save(customer1);

        Customer customer2 = new Customer(10, "Thomas", "Kartoffel");
        customerRepository.save(customer2);
    
        Order order = new Order(1L);
        orderRepository.save(order);
        
        OrderPosition position = new OrderPosition();
        position.setAnzahl(1);
        position.setOrder(order);
        position.setOrderId(order.getOrderId());
        position.setProductId(product3.getId());
        position.setProduct(product3);
        orderService.addPosition(position);
    }

        
}
